<?php
defined('SYSPATH') or die('No direct script access.') ;
/**
  * $Id: certshop.php 4 2011-12-15 09:28:04Z 周永隆 $
 */
class Cli_Certshop extends CLI
{
	
	public function main()
	{			
        $shop_id_array = DB::select( 'shop_id' )
            ->from( 'shops' )
            ->fetch_all();
        echo '总共'.count( $shop_id_array ).'个店铺\n';
        $cert = 0;
        foreach ( $shop_id_array as $shop_id )
        {
            $count = DB::select( DB::Expr( 'count(*)' ) )
                ->from( 'goods' )
                ->where( 'shop_id', '=', $shop_id  )
                ->where( 'handle_id', 'in', array( 1, 2, 3, 4 ) )
                ->fetch_one();
            if ( $count > 0 )
            {
                DB::update( 'shops' )
                    ->set( array( 'cert_type' => 1 ) )
                    ->where( 'shop_id', '=', $shop_id )
                    ->execute();
                $cert++;
            }
            echo '>';
        }
        echo '\n更新'.$cert.'个店铺\n';
		CLI::output("更新完毕\n");
	}
}